<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>watch</title>
    <script src="./js/vue.min.js"></script>
  </head>
  <body>
    <div id="root">
      <p>name: {{name}}</p>
      <br />
      <button @click="changeName">change name</button>
    </div>
    <script>
      // v-model.trim 去掉前后空格
      // v-model.lazy 失去焦点获取数据
      // v-model.number 只能响应数字
      new Vue({
        el: "#root",
        name: "Watch",
        data() {
          return {
            name: "张三",
            info: {
              city: "北京",
            },
          };
        },
        methods: {
          changeName() {
            this.name = `张三 ${Date.now()}`;
          },
        },
        watch: {
          // name(newVal, val) {
          //     console.log('name', newVal, val)
          // },
          name: {
            handler(newVal, val) {
              console.log("name", newVal, val);
            },
            immediate: true, // 立刻触发
            deep: true, // 深度监听
          },
        },
      });
    </script>
  </body>
</html>
